layui.use(['layer', 'form', 'table', 'jquery', 'laydate', 'admin', 'ax'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ = layui.$;
    var $ax = layui.ax;
    var laydate = layui.laydate;
    var admin = layui.admin;

    /**
     * 系统管理--维修日志
     */
    var record = {
        tableId: "maintainTable",    //表格id
        condition: {
            bridgeName:""
        }
    };

    /**
     * 初始化表格的列
     */
    record.initColumn = function () {
        return [[
            // {type: 'checkbox'},
            {field: 'id', hide: true, sort: true, title: '维修记录id'},
            {field: 'bridgeId', sort: true, title: '桥梁id'},
            {field: 'bridgeName', sort: true, title: '桥梁名称'},
            {field: 'beamNo', sort: true, title: '梁编号'},
            {field: 'maintainDate', sort: true, title: '维修日期'},
            {field: 'person', sort: true, title: '维修人'},
            {field: 'type', sort: true, title: '维修类型'},
            {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 280}
        ]];
    };


    // 渲染表格
    var tableResult = table.render({
        elem: '#' + record.tableId,
        url: Feng.ctxPath + '/maintainRecord/pageAll',
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        cols: record.initColumn()
    });


    /**
     * 点击查询按钮
     */
    record.search = function () {
        var queryData = {};
        queryData['bridgeName'] = $("#bridgeName").val();
        table.reload(record.tableId, {where: queryData});
    };

    /**
     * 弹出添加用户对话框
     */
    record.openAddRecord = function () {
        admin.putTempData('formOk', false);
        top.layui.admin.open({
            type: 2,
            title: '添加用户',
            content: Feng.ctxPath + '/maintainRecord/record_add',
            end: function () {
                admin.getTempData('formOk') && table.reload(MgrUser.tableId);
            }
        });
    };

    /**
     * 点击编辑桥梁
     *
     * @param data 点击按钮时候的行数据
     */
    record.onEditRecorde = function (data) {
        admin.putTempData('formOk', false);
        top.layui.admin.open({
            type: 2,
            title: '修改日志',
            area: ['800px', '600px'],
            content: Feng.ctxPath + '/maintainRecord/record_edit?id=' + data.id,
            end: function () {
                admin.getTempData('formOk') && table.reload(record.tableId);
            }
        });
    };

    /**
     * 导出excel按钮
     */
    record.exportExcel = function () {
        var checkRows = table.checkStatus(record.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        record.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        record.openAddRecord();
    });

    // 导出excel
    $('#btnExp').click(function () {
        record.exportExcel();
    });

    // 工具条点击事件
    table.on('tool(' + record.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            record.onEditRecorde(data);
        }
    });




});
